package com.xbts.system.domain;

import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.xbts.common.annotation.Excel;
import com.xbts.common.core.domain.BaseEntity;
import com.xbts.common.utils.StringUtils;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.apache.ibatis.annotations.Insert;

import javax.validation.constraints.NotEmpty;

/**
 * 片区管理对象 party_area
 *
 * @author xbts
 * @date 2023-06-12
 */
@Data
@ApiModel("片区管理对象")
@TableName("party_area")
public class PartyArea extends BaseEntity {

    private static final long serialVersionUID = 1L;

    /**
     * 片区编号
     */
    @TableId
    private String areaId;

    /**
     * 片区名称
     */
    @Excel(name = "片区名称")
    @ApiModelProperty("片区名称")
    @NotEmpty(message = "片区名称不能为空")
    private String areaName;

    /**
     * 片区名称
     */
    @Excel(name = "片区编号")
    @ApiModelProperty("片区编号")
    // 新增时才校验编号是否为空
    @NotEmpty(message = "片区编号不能为空", groups = Insert.class)
    private String areaCode;

    public <T> QueryWrapper<T> queryWrapper() {
        QueryWrapper<T> queryWrapper = new QueryWrapper<>();
        if (StringUtils.isNotEmpty(areaName)){
            queryWrapper.like("area_name", areaName.trim());
        }
        if (StringUtils.isNotEmpty(areaCode)){
            queryWrapper.like("area_code", areaCode.trim());
        }
        return queryWrapper;
    }
}